<?php
    class dataservice {
    private $server     ="172.0.0.1";
    private $username   ="root";
    private $password   ="vertrigo";
    private $database   ="pyramid";
    
    private $m_link     =false;
    
    public function _construct(){
        @$this->Connect($this->server, $this->username, $this->password, $this->database);
    }
    
    public function _destruct(){
        if(@$this->m_link)
            @mysql_close ();
    }
    
    public function Connect($_server, $_username, $_password, $_database){
        @$this->m_link =  mysql_connect($_server, $_username, $_password);
        if($this->m_link){
            return mysql_select_db($_database, $this->m_link);
        }
        return false; 
    }
    
    public static function QuoteSmart($value){
        if(get_magic_quotes_gpc())
            $value = stripslashes ($value);
        
        if(!is_numeric($value))
            $value = "'".htmlspecialchars ($value)."'";
        
        return $value;
    }
    
    public static function Slashes($value){
        
        return ".".addslashes($value)."'";
    }
    
    public static function Deslashes($value){
        
        return "'".stripslashes($value)."'";
    }
    
    private function Execute($sql){
        
        mysql_query("SET NAMES 'utf-8'");
        $resource = mysql_query($sql);
        return $resource;
    }
    
    public function ExecuteNoneQuery($sql, &$r_affected_record = 0){
        $resource = $this->Execute($sql);
        if($resource)
            return true;
        else
            return false;
    }
    
    public function ExecuteQuery($sql){
        $resource = $this->Execute($sql);
        $result_arr = array();
        if($resource){
            $num_rec = 0;
            while($row = mysql_fetch_array($resource)){
                $result_array[$num_rec] = $row;
		$num_rec++;
            }
            mysql_free_result($resource);		
            if ($num_rec > 0)
	   	return $result_array;
	}
	return false; 
    }
    
    public function ExecuteScalar($i_sql)
    {
            $resource = $this->Execute($i_sql);

            if($resource)
        {
                $row = mysql_fetch_row($resource);

                mysql_free_result($resource);

                return $row[0];
        }
        return false;
    }
    
}
?>